package com.mogujie.tt.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.mogujie.tt.R;
import com.mogujie.tt.imservice.event.OpenpwdEvent;
import com.mogujie.tt.ui.activity.CreateGesturePasswordActivity;
import com.mogujie.tt.ui.activity.NumPwdActivity;
import com.mogujie.tt.ui.base.TTBaseFragment;

import de.greenrobot.event.EventBus;

/**
 * Created by Administrator on 2015/11/4.
 */
public class OpenPwdFragment extends TTBaseFragment {

    private View curView;
    private View OpenGestu;
    private View OpenNum;
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup vg, Bundle bundle) {
        if (null != curView) {
            ((ViewGroup) curView.getParent()).removeView(curView);
            return curView;
        }
        curView = inflater.inflate(R.layout.tt_fragment_openpwd, topContentView);
        initRes();
        return curView;
    }

    private void initRes() {
        EventBus.getDefault().register(this);
        setTopTitle(getActivity().getString(R.string.gestures_page_name));
        setTopLeftButton(R.drawable.tt_top_back);
        topLeftContainerLayout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                getActivity().finish();
            }
        });
        setTopLeftText(getResources().getString(R.string.top_left_back));
        initView();
    }

    private void initView() {

        OpenGestu = curView.findViewById(R.id.sopenpwd);
        OpenNum = curView.findViewById(R.id.zopenpwd);

        OpenGestu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getActivity(), CreateGesturePasswordActivity.class));
            }
        });

        OpenNum.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(getActivity(), NumPwdActivity.class));
            }
        });

    }

    public void onEventMainThread(OpenpwdEvent event) {
        switch (event) {
            case SUCCEED:
                getActivity().finish();
                EventBus.getDefault().unregister(this);
                break;
            case BE_DEFEATER:
                break;
        }
    }


    @Override
    protected void initHandler() {

    }
}
